package com.example.demo.dao;

import com.example.demo.demos.Comment;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;

import java.util.List;
import java.util.Map;

public interface CommentDao extends JpaRepository<Comment,Integer> {


    @Query(value = "SELECT " +
            " c.*, " +
            "u.nickname, " +
            "u.avatar, " +
            "(select nickname from user where id =(select user_id from comment where id=(SELECT reply_id from comment where id =c.id )))as replyNickname " +
            "FROM " +
            "comment c " +
            "JOIN user u on c.user_id = u.id " +
            "WHERE " +
            "c.circle_id =?1",nativeQuery = true)
    List<Map<String,Object>> getList(int circleId);

    @Query(value = "SELECT " +
            " c.*, " +
            "u.nickname, " +
            "u.avatar, " +
            "(select nickname from user where id =(select user_id from comment where id=(SELECT reply_id from comment where id =c.id )))as replyNickname " +
            "FROM " +
            "comment c " +
            "JOIN user u on c.user_id = u.id " +
            "WHERE " +
            "c.circle_id =?3 order by time desc LIMIT ?1,?2",nativeQuery = true)
    List<Map<String, Object>> getAdminList(int i, int pageSize, int circleId);
    @Query(value = "select count(id) from comment where circle_id = ?1",nativeQuery = true)
    int getCountByCircleId(int circleId);
}
